define(['jquery', 'bootstrap', 'backend', 'table', 'form','code'], function ($, undefined, Backend, Table, Form,Code,undefined) {
    // console.log(location.search);
    var Controller = {
        //此方法返回日期
        today: function (AddDayCount) {
            const dd = new Date();
            dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
            let y = dd.getFullYear();
            let m = dd.getMonth()+1;//获取当前月份的日期
            let d = dd.getDate();
            //判断月
            if (m < 10) {
                m = "0" + m;
            }
            //判断日
            if (d < 10) {
                d = "0" + d;
            }
            return y + "-" + m + "-" + d;
        },

        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'short/chain/data/index' + location.search,
                    // add_url: 'short/chain/config/add',
                    edit_url: 'short/chain/data/edit',
                    // del_url: 'short/chain/config/del',
                    // multi_url: 'short/chain/config/multi',
                    // import_url: 'short/chain/config/import',
                    table: 'short_chain_config',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                pageSize:25,
                searchFormVisible: true, //是否始终显示搜索表单
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('ID'), operate: false,sortable: true},
                        {field: 'title', title: __('短链信息'), operate: false,sortable: true},
                        // {field: 'orginal_url', title: __('跳转链接'), operate: 'like'},
                        {
                            field: 'orginal_url',
                            title: __('跳转链接'),
                            operate: false,
                            cellStyle:function (value,row,index,field) {
                                return {
                                    css: {
                                        "min-width": "150px",
                                        "white-space": "nowrap",
                                        "text-overflow": "ellipsis",
                                        "overflow": "hidden",
                                        // "color": "red",
                                        "max-width":"300px"
                                    }
                                };
                            },
                            // editable: true
                        },

                        {
                            field: 'group_id',
                            title: __('分组'),
                            visible: false,
                            operate: 'like',
                            addClass: "selectpage",
                            // defaultValue: 10,
                            extend: "data-source='short/chain/group' data-field='name' data-primary-key='id'"
                        },
                        {
                            field: 'short_url',
                            title: __('短链'),
                            operate: false,
                            // editable: true
                        },
                        {
                            field: 'createtime',
                            title: __('时间'),
                            visible: false,
                            operate:'RANGE',
                            addclass:'datetimerange',
                            // autocomplete:false,
                            // align:'left',
                            defaultValue: this.today(0) + " 00:00:00 - " + this.today(0) + ' 23:59:59',
                            formatter: Table.api.formatter.datetime,
                            // datetimeFormat: "YYYY-MM-DD",
                            cellStyle: Controller.api.formatter.css,
                            // width: '2000rem'

                        },
                        {field: 'pv', title: __('PV'), operate: false,sortable: true},
                        {field: 'uv', title: __('UV'), operate: false,sortable: true},
                        {field: 'ip', title: __('IP'), operate: false,sortable: true},
                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons:[
                                {
                                    name:'static',//名称
                                    text:'数据',
                                    title:'统计',
                                    extend:'data-area=["750px","1000px"]',
                                    classname: 'btn btn-xs btn-info btn-view btn-dialog',
                                    icon: 'fa fa-yelp',//图标 可在添加菜单规则处 搜索图标见示例图
                                    url: 'short/chain/data/static_data?group_id={group_id_search}',//接口地址 控制器名/方法名
                                    refresh:true
                                }
                            ],

                            formatter: function (value, row, index) {
                                //var timestamp = parseInt((new Date()).getTime() / 1000);
                                var that = $.extend({}, this);
                                $(table).data("operate-edit", null); // 列表页面隐藏 .编辑operate-edit  - 删除按钮operate-del
                                // $(table).data("operate-edit", true);
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);

                            }
                        },
                        {field: 'group_id_one', title: __('IP'), operate: false,visible: false},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {

                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                css:function(){
                    return{
                        css:{
                            "min-width":"400px !important",
                        }
                    };
                },
            }
        }
    };
    return Controller;
});
